package com.sgb.kjwl.view.ui.activity.material.hall;

import android.content.Intent;
import android.text.TextUtils;

import com.chuanglan.shanyan_sdk.OneKeyLoginManager;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.LoginEntity;
import com.sgb.kjwl.model.entity.TenderListEntity;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.user.OneKeyLoginEntity;
import com.sgb.kjwl.repository.PickRepertory;
import com.sgb.kjwl.view.ui.activity.pick.PickInquireByLetterActivity;
import com.sgb.kjwl.view.ui.activity.pick.ReportActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.SetPwdActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.dialog.DialogHelper;
import com.im.immodel.IMUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 招采模块招标搜索
 */
public class NewPickSigningUpModel extends BaseViewModel {

    private NewPickSigningUpListFragment newPickSigningUpListFragment;
    private PickRepertory repertory;
    private int page = 1;
    private Map map;

    public NewPickSigningUpModel(NewPickSigningUpListFragment newPickSigningUpListFragment, PickRepertory repertory) {
        this.newPickSigningUpListFragment = newPickSigningUpListFragment;
        this.repertory = repertory;
    }

    public void getList(List<String> cityNo, List<String> typeNo, List<String> scaleNo, List<String> statusNo, boolean b) {
        map = new HashMap();
        page = b ? page + 1 : 1;
//        map.put("areacode", repertory.getAreaCode());
        if (cityNo.size() != 0)
            map.put("city", cityNo.get(0));
        map.put("comName", "");
        map.put("limit", 10);
        map.put("name", "");
        map.put("page", page);
        if (statusNo.size() != 0)
            map.put("state", statusNo.get(0));
        if (typeNo.size() != 0)
            map.put("type", typeNo.get(0));

        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().getTenderList(map).enqueue(new Callback<BaseEntity<List<TenderListEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<TenderListEntity>>> call, Response<BaseEntity<List<TenderListEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null)
                    return;
                newPickSigningUpListFragment.showList(response.body().getData(), b);
            }

            @Override
            public void onFailure(Call<BaseEntity<List<TenderListEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }


    public void getNewList(String cityNo, String typeNo, String priceNo, String time, boolean b, String search, String verticalType, String biddingMethod, String areaCode, String goodsType, String sortMethod) {
        map = new HashMap();
        page = b ? page + 1 : 1;
        if (!"".equals(areaCode) && areaCode != null)
            map.put("areacode", areaCode);
        if (!"".equals(cityNo) && cityNo != null)
            map.put("city", cityNo);
        map.put("comName", "");
        map.put("limit", 10);
        map.put("name", search);
        map.put("page", page);
        if (!"".equals(time) && time != null)
            map.put("time", time); // 报名结束时间
        if (!"".equals(verticalType) && verticalType != null)
            map.put("verticalType", verticalType); // 报名方式：1、资格预审；2、资格后审；3、报价即报名
        if (!"".equals(priceNo) && priceNo != null)
            map.put("price", priceNo);
        if (!"".equals(typeNo) && typeNo != null)
            map.put("type", typeNo); // 招标类型
        if (!TextUtils.isEmpty(goodsType)) {
            map.put("goodsType", goodsType); // 清单分类类型
        }
        if (!TextUtils.isEmpty(biddingMethod)) {
            map.put("biddingMethod", biddingMethod); // 招标方式 1、公开招标；2、邀请招标
        }
        map.put("sortMethod", Integer.valueOf(sortMethod));
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().tenderApplyingList(map).enqueue(new Callback<BaseEntity<List<TenderListEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<TenderListEntity>>> call, Response<BaseEntity<List<TenderListEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null)
                    return;
                newPickSigningUpListFragment.showList(response.body().getData(), b);
            }

            @Override
            public void onFailure(Call<BaseEntity<List<TenderListEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }


    public void getPickTimes() {
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().getPickTimes().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setTimeDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getSelecteScaleData() {
        APIManager.getInstance().getPickAPI().getProjectScale("0").enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setPriceDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {

            }
        });
    }

    public void getPriceData() {
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().getProjectMoney().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setPriceDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getProvinceData() {
        Map map = new HashMap();
        map.put("areaCode", repertory.getAreaCode());
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().getLocationNew(map).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setProvinceDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCityData(String province, boolean isShowDialog) {
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().getAreaSecond(province).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setCityDatas(response.body().getData(), isShowDialog);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getTenderNewTypeList() {
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().getTenderNewTypeList().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setTenderTypeDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getFilterTypeData() {
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().tenderNewTypeList().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setTypeDatas(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    //新增类型过滤接口
    public void getTenderGoodsCategoryAllList(String category) {
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        Map map = new HashMap();
        map.put("type", category);
        APIManager.getInstance().getPickAPI().getTenderGoodsCategoryAllList(map).enqueue(new Callback<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>> call, Response<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setTenderGoodsCategoryAllList(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public String getAreaCode() {
        return repertory.getAreaCode();
    }

    public void tenderApplyingListMap(String distance, String typeNo, String price, boolean b, String searchName, String goodsType, double latitude, double longitude, String verticalType, String biddingMethod) {
        map = new HashMap();
        page = b ? page + 1 : 1;
        if (!"".equals(distance) && distance != null)
            map.put("distance", distance);
        map.put("limit", 10);
        map.put("keyword", searchName);
        map.put("page", page);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        if (!"".equals(typeNo) && typeNo != null)
            map.put("type", typeNo);
        if (!"".equals(price) && price != null)
            map.put("price", price);
        if (!TextUtils.isEmpty(goodsType)) {
            map.put("goodsType", goodsType);
        }
        if (!TextUtils.isEmpty(biddingMethod)) {
            map.put("biddingMethod", biddingMethod); // 招标方式 1、公开招标；2、邀请招标
        }
        if (!TextUtils.isEmpty(verticalType))
            map.put("verticalType", verticalType); // 报名方式：1、资格预审；2、资格后审；3、报价即报名
        if (newPickSigningUpListFragment.getActivity() != null && !newPickSigningUpListFragment.getActivity().isDestroyed() && !newPickSigningUpListFragment.getActivity().isFinishing()) {
            DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getPickAPI().tenderApplyingListMap(map).enqueue(new ICallBack<BaseEntity<List<TenderListEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<TenderListEntity>> data) {

                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.showMapList(data.getData(), false, b);
                    newPickSigningUpListFragment.setTenderListEntityMapList(data.getData(), b, page);
                } else {
                    MToast.showToast(newPickSigningUpListFragment.getActivity(), data.getMsg());
                }

            }

            @Override
            public void onFail() {
                super.onFail();
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    public void getSortTypeData() {
        APIManager.getInstance().getPickAPI().getTenderNoticeSortSelect().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (response.body().getData() != null) {
                        newPickSigningUpListFragment.setSortDatas(response.body().getData());
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {

            }
        });
    }

    public void getUrlSettingTender(String id) {
        DialogHelper.showProgressDialog2(newPickSigningUpListFragment.getActivity(), null, "加载中", 0, true, null, false);
        APIManager.getInstance().getPickAPI().getUrlSetting("FrontDeskBidding").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    MLog.d("api", "H5跳转链接  " + url);
                    newPickSigningUpListFragment.getUrl(url, id);
                } else {
                    MToast.showToast(newPickSigningUpListFragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void findCustomerServiceImAccount(String customerServiceContactsId) {
        DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("customerServiceContactsId", customerServiceContactsId);
        APIManager.getInstance().getPickAPI().getfindCustomerServiceImAccount(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    newPickSigningUpListFragment.checkAllowDialog(response.body().getMsg());
                } else {
                    Object data = response.body().getData(); // 接口返回的是String类型
                    String dataIMid = response.body().getData().toString();
                    IMUtils.getInstance().buildSingleTalking(dataIMid);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    public void checkAllowTenderQuestion(String tenderNo, int tenderingType) {
        DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("tenderNo", tenderNo);
        APIManager.getInstance().getPickAPI().checkAllowTenderQuestion(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_FAIL)) {
                    newPickSigningUpListFragment.checkAllowDialog(response.body().getMsg());
                } else {
                    PickInquireByLetterActivity.start(newPickSigningUpListFragment.getActivity(), tenderNo, "activity", tenderingType);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    public void editTender(String tenderNo, int position) {
        Map map = new HashMap();
        map.put("tenderNo", tenderNo);
        DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().editTender(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    newPickSigningUpListFragment.setTvIsGz(position);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void countByBusiness(String businessNo) {
        DialogHelper.showProgressDialog(newPickSigningUpListFragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("businessNo", businessNo);
        map.put("businessType", 1);
        APIManager.getInstance().getPickAPI().countByBusiness(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (!"可进行举报监督操作".equals(response.body().getData())) {
                        newPickSigningUpListFragment.checkAllowDialog(response.body().getData().toString());
                    }else{
                        ReportActivity.start(newPickSigningUpListFragment.getActivity(), businessNo, "1");
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void oneKeyLogin(OneKeyLoginEntity oneKeyLoginEntity) {
        DialogHelper.showProgressDialog(newPickSigningUpListFragment.getContext(), null, "登录中", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().oneClickLogin(oneKeyLoginEntity).enqueue(new Callback<BaseEntity<LoginEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<LoginEntity>> call, Response<BaseEntity<LoginEntity>> response) {

                DialogHelper.dismissProgressDialog();
                if (response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    OneKeyLoginManager.getInstance().finishAuthActivity();
                    if (response.body().getData().isNeedRegister()) {
                        Intent intent = new Intent(newPickSigningUpListFragment.getContext(), SetPwdActivity.class);
                        intent.putExtra("mobile", response.body().getData().getPhone());
                        newPickSigningUpListFragment.startActivity(intent);
                    } else {
                        //登录成功逻辑
                        loginImModel(response);

                        /*saveUserInfo(response.body().getData());
                        activity.loginSucceed(response.body().getData(), response.body().getData().getPhone());
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, response.body().getData().getToken());
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, response.body().getData().getPhone());
                        JPushInterface.setAlias(activity, 1, response.body().getData().getPhone());
                        getUserInfo();*/
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<LoginEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //网易IM登陆
    private void loginImModel(Response<BaseEntity<LoginEntity>> response) {
//        NimUIKit.login(new LoginInfo(response.body().getData().getImAccount(), response.body().getData().getImToken()), new RequestCallback<LoginInfo>() {
//            @Override
//            public void onSuccess(LoginInfo param) {
                DialogHelper.dismissProgressDialog();
                SharedPreferenceUtil.getInstance().cleatData();
                saveUserInfo(response.body().getData());
                MToast.showToast(newPickSigningUpListFragment.getContext(), "登录成功");
                newPickSigningUpListFragment.loginSucceed(response.body().getData(), response.body().getData().getPhone());
                SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, response.body().getData().getToken());
                SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, response.body().getData().getPhone());
                JPushInterface.setAlias(newPickSigningUpListFragment.getContext(), 1, response.body().getData().getPhone());
                getUserInfo();
//            }
//
//            @Override
//            public void onFailed(int code) {
//                DialogHelper.dismissProgressDialog();
//            }
//
//            @Override
//            public void onException(Throwable exception) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }

    public void getUserInfo() {
        DialogHelper.showProgressDialog(newPickSigningUpListFragment.getContext(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().getUserInfo().enqueue(new Callback<BaseEntity<UserMsgEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<UserMsgEntity>> call, Response<BaseEntity<UserMsgEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getData() == null) return;
                if (response.body().getState().equals("ok")) {
                    newPickSigningUpListFragment.getUserMsgSucceed(response.body().getData());
                } else {
                    MToast.showToast(newPickSigningUpListFragment.getContext(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<UserMsgEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    private void saveUserInfo(LoginEntity loginEntity) {
        repertory.saveToken(loginEntity.getToken());
        repertory.saveAccount(loginEntity.getPhone());

//        NimUIKit.setAccount(loginEntity.getImAccount());
//        AVChatKit.setAccount(loginEntity.getImAccount());
//        Preferences.saveUserAccount(loginEntity.getImAccount());
//        Preferences.saveUserToken(loginEntity.getImToken());
    }
}
